import Vue from 'vue'
import VueRouter from 'vue-router'

// 同一个页面跳转同一个路由也会出现同样的问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    //redirect:"/platform/home"
    redirect:"/login"
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import( '../views/login.vue')
  },
  {
    path: '/register',
    name: 'Register',
    component: () => import( '../views/register.vue')
  },
  {
    path: '/platform',
    name: 'Platform',
    component: () => import( '../views/platform/platform.vue'),
    children:[
      {
        path: '/platform/home',
        name: 'Home',
        component: () => import( '../views/platform/home/home.vue')
      },
      {
        path: '/platform/user',
        name: 'User',
        component: () => import( '../views/platform/user/user.vue')
      },
      {
        path: '/platform/itemList',
        name: 'ItemList',
        component: () => import( '../views/platform/itemList/item_list.vue')
      },
      {
        path: '/platform/createItem',
        name: 'CreateItem',
        component: () => import( '../views/platform/createItem/createItem.vue')
      },
      {
        path: '/platform/blacklist',
        name: 'Blacklist',
        component: () => import( '../views/platform/blacklist/blacklist.vue')
      },
      {
        path: '/platform/settleItem',
        name: 'SettleItem',
        component: () => import( '../views/platform/settleItem/settleItem.vue')
      },
      {
        path: '/platform/key_overdue',
        name: 'Key_overdue',
        component: () => import( '../views/platform/key_overdue/key_overdue.vue')
      },
      {
        path: '/platform/help_center',
        name: 'Help_center',
        component: () => import( '../views/platform/help_center/help_center.vue')
      }
    ]
  }
]

const router = new VueRouter({
  //mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to,from,next)=>{
	// 从from到to  // to就是上面配置的路由
	console.log("to:",to);
	document.title="下单系统";
	//document.title=to.matched[0].meta.title;
	// document.title=to.meta.title;
	next();
})


router.afterEach((to,from,next) => {
	document.body.scrollTop =0;
	document.documentElement.scrollTop = 0;

});

export default router
